/**
 * This is webServer's Common module
 * @module
 */

/**
 * server port
 */
const PORT = 3010;

// Log facility
const bunyan = require("bunyan");

// Rotating write stream
const rfs = require("rotating-file-stream");
/* ----------------------------------------------------------
 *                   Logging facility
 * ----------------------------------------------------------*/

// Log stream
let logStream;
if (process.env.NODE_ENV === "production") {
  logStream = rfs.createStream("holly.log", {
    size: "100M",
    interval: "1M",
    path: "/var/tmp/holly",
    compress: "gzip",
    maxFiles: 12,
  });
} else {
  logStream = process.stdout;
}

// Log interface
const log = bunyan.createLogger({
  name: "holly",
  stream: logStream,
  level: "trace",
});
// Access log stream
let accessLogStream;
if (process.env.NODE_ENV === "production") {
  accessLogStream = rfs.createStream("holly_access.log", {
    size: "100M",
    interval: "1M",
    path: "/var/tmp/holly",
    compress: "gzip",
    maxFiles: 12,
  });
} else {
  accessLogStream = process.stdout;
}

/**
 * server host
 */
const HOST_NAME = "http://localhost";
/**
 * Database connection address
 */
const DATA_BASE = process.env.MONGODB_URI || "mongodb://localhost/lilyweb";




/* ----------------------------------------------------------
 *                       Exports
 * ----------------------------------------------------------*/

module.exports = {
  log,
  accessLogStream,
  PORT: PORT,
  HOST_NAME: HOST_NAME,
  DATA_BASE,
};
